<?php
include "../fun.php";
$db=conndb();
$username=$_POST["username"];
$password=base64_encode($_POST["password"]);
$sql="select * from user where username='{$username}'";
$res=query1($db,$sql,false);
if (!$res) {
    // echo "<script>alert('用户名错误');history.back();</script>";
    echo json_encode(["code"=>1,"msg"=>"用户名错误"]);
}else if ($password!=$res["password"]) {
    echo json_encode(["code"=>1,"msg"=>"密码错误"]);
    // echo "<script>alert('密码错误');history.back();</script>";
}else {
    session_start();
    $_SESSION["id"]=$res["id"];
    $_SESSION["realname"]=$res["realname"];
    $data=["id"=>$_SESSION["id"],"access_token"=>$_SESSION["realname"]];
    echo json_encode(["code"=>0,"msg"=>"用户名错误","data"=>$data]);
    // echo "<script>alert('登录成功');location.href='/admin/index.html';</script>";
}
?>